package com.dries.security.core.validate.code.captcha.sms;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.dries.security.core.properties.SecurityCoreProperties;
import com.dries.security.core.validate.code.captcha.SysCaptcha;
import com.dries.security.core.validate.code.captcha.ValidateCodeGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2020/9/8 19:17
 */
@Component("smsValidateCodeGenerator")
@Slf4j
public class SmsCodeGenerator  implements ValidateCodeGenerator {

    @Resource
    private SecurityCoreProperties coreProperties;

    @Override
    public SysCaptcha generate(ServletWebRequest request) {
        String code = RandomUtil.randomNumbers(coreProperties.getCode().getSms().getLength());
        return new SysCaptcha(IdUtil.simpleUUID(), code, coreProperties.getCode().getSms().getExpireIn());
    }
}
